﻿namespace Sgr.Utilities
{
    /// <summary>
    /// 环境变量帮助类
    /// </summary>
    public static class EnvironmentHelper
    {
        /// <summary>
        /// 按优先级获取环境变量值（Process > User > Machine）
        /// </summary>
        /// <param name="variable">环境变量名称</param>
        /// <returns>环境变量值，未找到或发生错误时返回null</returns>
        public static string? GetEnvironmentVariable(string variable)
        {
            try
            {
                return Environment.GetEnvironmentVariable(variable, EnvironmentVariableTarget.Process) ??
                    Environment.GetEnvironmentVariable(variable, EnvironmentVariableTarget.User) ??
                    Environment.GetEnvironmentVariable(variable, EnvironmentVariableTarget.Machine);
            }
            catch
            {
                return null;
            }
        }
    }
}